<template>
  <el-upload
    class="avatar-uploader"
    :action="$apis + '/common/Upload/UpImg'"
    :show-file-list="false"
    :on-success="handleAvatarSuccess"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
    <span v-else class="upIcon iconfont icon-shangchuan"></span>
  </el-upload>
</template>

<script setup>
import { ref } from "vue";
import { Plus } from "@element-plus/icons-vue";

const emit = defineEmits(["ok"]);

const imageUrl = ref("");

const handleAvatarSuccess = (response, uploadFile) => {
  imageUrl.value = response.data;
  emit("ok", response.data);
};
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 148px;
  height: 148px;
  display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #666f83;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: block;
  width: 148px;
  height: 148px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666f83;
  transition: all 0.3s linear;
}
.avatar-uploader:hover .el-upload {
  border: 1px dashed #05a165;
  color: #05a165;
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  text-align: center;
}
</style>
